<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>Learning JavaScript - Ch11 Chained Constructor</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		
		<style type="text/css">
			div#header {
				color: #0066FF;
				font-size: 25pt;
			}
			
			div#content {
				color: #B088FF;
				font-size: 12pt;
			}
		</style>
		
		<!-- embed jquery by google，藉由google嵌入jquery 1.6.2 -->
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		<script type="text/javascript" language="javascript">
			google.load( "jquery", "1.6.2" );
		</script>
		<script type="text/javascript">
		
			var Tune = function( title, type ) {
				this.title = title;
				this.type = type;
				var that = this;
				
				this.getTitle = function() {
					return this.title;
				};
				this.getType = function() {
					return this.type;
				};
				this.showDetails = function() {
					return {
						title: that.title,
						type: that.type
					};
				};
			};
		
			var ArtistTune = function( title, type, artist ) {
				this.artist = artist;
				this.toString();
				Tune.apply( this, arguments );
				this.toString = function() {
					return "Artist: " + this.artist + ", Title: " + this.getTitle() + ", Type: " + this.getType();
				};
			};
		
			$( document ).ready( function() {
				var song = new ArtistTune( "Falling Grace", "latin-jazz", "Steve Swallow" );
				
				$( "#content" ).append( "song.toString(): " + song.toString() + "<br />");
				
				var songTitle = song.showDetails().title;
				var songType = song.showDetails().type;
				$( "#content" ).append( "songTitle: " + songTitle + ", songType: " + songType + "<br />" );
			});
			
		</script>
		
	</head>
	
	<body>
		<div title="temp1" id="header">Learning JavaScript Ch11</div>
		<div title="temp1" id="content"></div>
	</body>
</html>